Dataset
Dataset
Base class for streaming datasets compatible with synalinks trainers.
Trainer.fit/evaluate/predict(x=...) accepts a Python generator that
yields (inputs,) or (inputs, targets) tuples — one tuple per
batch. See synalinks/src/trainers/data_adapters/generator_data_adapter.py
and the dispatch in synalinks/src/trainers/data_adapters/__init__.py.
Subclasses implement _iter_rows() as a generator yielding raw row
dicts (one per source example). The base class' __iter__ then
renders each row through the Jinja2 templates, validates the shape,
and yields batched (x, y) numpy object arrays — including the
repeat expansion. Calling the dataset returns a fresh generator
suitable for synalinks:
The shape of the per-row input/target objects is controlled by either
a Python DataModel class (input_data_model / output_data_model)
OR a raw JSON Schema (input_schema / output_schema). The two
are mutually exclusive on each side. With a class, rows are validated
via cls.model_validate_json(rendered). With a schema, rows are
wrapped as JsonDataModel(schema=..., json=json.loads(rendered)) —
the schema flows directly into the LM as a structured-output
constraint, so any JSON Schema feature (enum, const, oneOf, ...) is
supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data_model
|
DataModel
|
Python class describing batch
inputs. Defaults to |
None
|
input_schema
|
dict | str
|
Raw JSON Schema for batch inputs. May
be given as a dict or as a JSON-encoded string. Mutually
exclusive with |
None
|
input_template
|
str
|
Jinja2 template string used to render raw rows into the input shape. Required. |
None
|
output_data_model
|
DataModel
|
Python class describing batch
targets. Defaults to |
None
|
output_schema
|
dict | str
|
Raw JSON Schema for batch targets.
Mutually exclusive with |
None
|
output_template
|
str
|
Jinja2 template string used to render raw
rows into the target shape. Optional — when omitted, the
dataset is inputs-only and yields single-element |
None
|
batch_size
|
int
|
Number of examples per yielded batch. |
None
|
limit
|
int
|
Optional. Maximum number of raw (pre-repeat)
examples to iterate over. |
None
|
repeat
|
int
|
Number of consecutive copies to emit per raw
example. Defaults to 1 (no expansion). Setting
|
1
|
**kwargs
|
Any
|
Provider-specific fields forwarded by subclasses (e.g. HF dataset name, split, revision, API key, file path, ...). |
{}
|
Source code in synalinks/src/datasets/dataset.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
__call__()
__iter__()
Render rows through the templates and yield batches.
Yields (x, y) when an output_template is configured, or
single-element (x,) batches when it isn't. Honors limit
(caps raw rows), repeat (each raw example is emitted
repeat times in a row), and batch_size (size of the
yielded numpy object arrays; None accumulates everything into
a single trailing batch). The trailing partial batch is always
flushed at the end.
Source code in synalinks/src/datasets/dataset.py
__len__()
materialize()
Iterate the dataset to exhaustion and concatenate every batch.
Returns a single (x,) or (x, y) pair — numpy object
arrays of DataModel instances — suitable for
program.evaluate(x=x, y=y), program.fit(x=x, y=y),
or for slicing into train/test splits with
split_train_test.
This is the streaming-to-arrays bridge: any Dataset
subclass — HuggingFaceDataset, a custom CSV loader,
anything else — can be force-evaluated into in-memory NumPy
object arrays with a single method call. Use it for small
benchmark datasets that fit comfortably in memory; for huge
sources, iterate via ds() instead so rows stream on
demand.
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in synalinks/src/datasets/dataset.py
split_train_test(x, y, validation_split=0.2)
Deterministic head/tail split — for sources that ship a single labeled split (HumanEval, IFEval, BBH, TruthfulQA, BBQ, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input numpy object array. |
required |
y
|
ndarray
|
Target numpy object array. |
required |
validation_split
|
float
|
Fraction of the data that goes to
the test set. Defaults to |
0.2
|
Returns:
| Type | Description |
|---|---|
tuple
|
|